package com.xckj.cycling.fragment

import android.os.Bundle
import android.text.TextUtils
import com.xckj.cycling.framework.BaseActivityKt
import com.xckj.cycling.utils.JsAction
import com.xckj.cycling.utils.StatusBarHelper.showStatusBar
import com.xckj.cycling.view.CWebView

/**
 * 项目里用到的webview
 */
open class WebViewFragment : BaseWebViewFragment() {

    override fun initWebView(webView: CWebView?) {
        super.initWebView(webView)
    }

    override fun resumeAndNoHidden() {
        super.resumeAndNoHidden()
        showStatusBar(requireActivity(), true)
    }

    protected var _url: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (arguments != null) {
            _url = arguments!!.getString("url")
        }
    }

    override fun getJsAction(): Any {
        return JsAction((requireActivity() as BaseActivityKt), webView!!)
    }

    override fun getUrl(): String? {
        return if (!TextUtils.isEmpty(_url)) {
            _url!!
        } else "https://www.baidu.com"
    }

    companion object {
        /**
         * 构建一个新实例
         *
         * @param url
         * @return
         */
        fun getInstance(url: String?): WebViewFragment {
            val fragment = WebViewFragment()
            val bundle = Bundle()
            bundle.putString("url", url)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun listenLocation(): Boolean {
        return true
    }

}